#include "LumineUtils.hpp"
#include "Core/Context/LumineContext.hpp"
void Lumine::Utils::execSingleTimeCmds(const std::function<void(const vk::raii::CommandBuffer &)> &cmds)
{
    // 获取核心资源
    auto &device = LumineContext::Get().Device();
    vk::Queue graphicQueue = LumineContext::Get().GraphicQueue();

    vk::CommandPoolCreateInfo poolInfo(vk::CommandPoolCreateFlagBits::eTransient | vk::CommandPoolCreateFlagBits::eResetCommandBuffer, LumineContext::Get().GraphicIndex());
    vk::raii::CommandPool commandPool(device, poolInfo);

    vk::CommandBufferAllocateInfo allocInfo(*commandPool, vk::CommandBufferLevel::ePrimary, 1);
    vk::raii::CommandBuffers commandBuffers(device, allocInfo);
    vk::raii::CommandBuffer &commandBuffer = commandBuffers[0];

    commandBuffer.begin(vk::CommandBufferBeginInfo(vk::CommandBufferUsageFlagBits::eOneTimeSubmit));
    cmds(commandBuffer);
    commandBuffer.end();

    vk::SubmitInfo submitInfo(0,nullptr,nullptr,1,&*commandBuffer);
    graphicQueue.submit(submitInfo,nullptr);
    graphicQueue.waitIdle();
}